/*------------------------------------------------------------------------------------------------------------------------------------------
--		SOURCE FILE:	Command.cpp   -	Represents the "Application Layer" of the ISO model.  Handles all user interaction with the screen
--										and keyboard.  
--
--		PROGRAM:		Wireless Modem Protocol Driver
--
--		FUNCTIONS:		void callMenu(HWND hwnd, PTTYINFO pinfo, WPARAM wParam)
--						void displayChar(char charRead, PTTYINFO pinfo) 
--						void clearLine(char direction, PTTYINFO pinfo)
--						void clearScreen(char direction, PTTYINFO pinfo)
--						void wmPaint(HWND hwnd, PTTYINFO pinfo)
--						void wmVscroll(HWND hwnd, WPARAM wParam, PTTYINFO pinfo)
--						void wmSize(HWND hwnd, UINT message, LPARAM lParam, PTTYINFO pinfo)
--						void wmCreate(HWND hwnd, PTTYINFO pinfo)
--						void wmSetFocus(HWND hwnd, PTTYINFO pinfo) 
--						void wmKillFocus(HWND hwnd)
--						void wmInputLang(WPARAM wParam)
						void initializePdata(PTTYINFO pinfo) 
--
--		DATE:			October 24, 2011
--
--		REVISIONS:		2.0
--
--		DESIGNER:		Chris Sim
--
--		PROGRAMMER		Mike Zobac/Chris Sim
--
--		NOTES:			All of these functions are passed a pointer to a TTYINFO struct.  This structure contains all of the variables which
--						would otherwise have to be global, or extern globals.
--------------------------------------------------------------------------------------------------------------------------------------------*/



#include "Command.h"
#include "Connect.h"
#include "Control.h"
#include "Config.h"
#include <mbstring.h>



static DWORD    dwCharSet = DEFAULT_CHARSET ;
HDC             hdc ;
SCROLLINFO		si ;

/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		callMenu
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Chris Sim
--
--		PROGRAMMER:		Chris Sim
--
--		INTERFACE:		void callMenu(HWND hwnd, PTTYINFO pinfo, WPARAM wParam)
--
--		RETURNS:		void
--
--		NOTES:			Processes messages sent from the menu at the top left corner of the window.   
--------------------------------------------------------------------------------------------------------------------------------------------*/

void callMenu(HWND hwnd, PTTYINFO pinfo, WPARAM wParam) {
    
    LPTSTR	lpszCommName1 = TEXT("COM1"), 
        lpszCommName2 = TEXT("COM2"), 
        lpszCommName3 = TEXT("COM3"), 
        lpszCommName4 = TEXT("COM4"), 
        lpszCommName5 = TEXT("COM5");

    char *filter = "All Files (*.*)\0*.*\0";
    HWND owner = NULL;
    char fileName[MAX_PATH] = "";
    char str [80];
    OPENFILENAME    ofn;

	switch (LOWORD (wParam))
	{
	case IDM_EXIT:
		ExitProcess(0);
		break;
	case IDM_COM1:
		
		pinfo->cc.dwSize = sizeof(COMMCONFIG);    
		pinfo->cc.wVersion = 0x100;
		GetCommConfig (pinfo->hPort, &pinfo->cc, &pinfo->cc.dwSize);   // set new settings to port
		if (!CommConfigDialog (lpszCommName1, hwnd, &pinfo->cc))
			break;
		setUserPrefs(pinfo);
		break;
	case IDM_COM2:
		CloseHandle (pinfo->hPort);      //CloseHandle(readThread);
		
		pinfo->hPort = initializePort(pinfo);			// reset the port
		
		pinfo->cc.dwSize = sizeof(COMMCONFIG);
		pinfo->cc.wVersion = 0x100;
		GetCommConfig (pinfo->hPort, &pinfo->cc, &pinfo->cc.dwSize);		// set new settings to port
		if (!CommConfigDialog (lpszCommName2, hwnd, &pinfo->cc))
			break;
		setUserPrefs(pinfo);
		break;
	case IDM_COM3:
		//CloseHandle(readThread);
		CloseHandle (pinfo->hPort);
		pinfo->hPort = initializePort(pinfo);
		//readThread = CreateThread(NULL, 0, ReadPort, NULL, 0, &rThread);
		pinfo->cc.dwSize = sizeof(COMMCONFIG);
		pinfo->cc.wVersion = 0x100;
		GetCommConfig (pinfo->hPort, &pinfo->cc, &pinfo->cc.dwSize);
		if (!CommConfigDialog (lpszCommName3, hwnd, &pinfo->cc))
			break;
		setUserPrefs(pinfo);
		break;
	case IDM_COM4:
		CloseHandle (pinfo->hPort);			//CloseHandle(readThread);
		
		pinfo->hPort = initializePort(pinfo);
		
		pinfo->cc.dwSize = sizeof(COMMCONFIG);
		pinfo->cc.wVersion = 0x100;
		GetCommConfig (pinfo->hPort, &pinfo->cc, &pinfo->cc.dwSize);
		if (!CommConfigDialog (lpszCommName4, hwnd, &pinfo->cc))
			break;
		setUserPrefs(pinfo);
		break;
	case IDM_COM5:
		CloseHandle (pinfo->hPort);		//CloseHandle(readThread);
		
		pinfo->hPort = initializePort(pinfo);
		
		pinfo->cc.dwSize = sizeof(COMMCONFIG);
		pinfo->cc.wVersion = 0x100;
		GetCommConfig (pinfo->hPort, &pinfo->cc, &pinfo->cc.dwSize);
		if (!CommConfigDialog (lpszCommName5, hwnd, &pinfo->cc))
			break;
		setUserPrefs(pinfo);
		break;

	case IDM_OPEN1:
		  
		  ZeroMemory(&ofn, sizeof(ofn));
		  ofn.lStructSize = sizeof(OPENFILENAME);
		  ofn.hwndOwner = owner;
		  ofn.lpstrFilter = filter;
		  ofn.lpstrFile = fileName;
		  ofn.nMaxFile = MAX_PATH;
		  ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
		  ofn.lpstrDefExt = "";
		  GetOpenFileName(&ofn);
		  pinfo->inputFile = fopen(ofn.lpstrFile,"r");
		break;

	case IDM_SEND1:
        
        //  Start the read thread
        
		pinfo->bReading = TRUE;
		if((pinfo->readThread = CreateThread(NULL, 0, ReadPort, pinfo, 0, &pinfo->rThread)) == INVALID_HANDLE_VALUE)
		{
			MessageBox(NULL, "Error creating READ thread", "", MB_OK);
			CloseHandle(pinfo->hPort);
			return;
		}

		
		// start Protocol thread

		if((pinfo->protocolThread = CreateThread(NULL, 0, Controlx, pinfo, 0, &pinfo->xThread)) == INVALID_HANDLE_VALUE)
        {
            MessageBox(NULL, "Error creating Protocol thread", "", MB_OK);
            CloseHandle(pinfo->hPort);
            return;
        }

		if(pinfo->inputFile != NULL)
		{
			SetEvent(pinfo->FrameToSend);
		}
		
		break;

	case IDM_HELP:
		MessageBox (hwnd, TEXT ("Google is your best friend :D"),    //Display !help box
			TEXT ("Need help?"), MB_OK | MB_ICONEXCLAMATION) ;
		break;

	case IDM_ABOUT:
		MessageBox (hwnd, TEXT ("Smart Terminal Emulator Pro 2011 \n\n(c) Chris Sim & Mike Zobac, 2011\n\nPurchase Inquiry:\tchrissim@live.ca\nTechnical Support:\tmikezobal@gmail.com"),
			TEXT ("STE Pro 2011"), MB_OK | MB_ICONINFORMATION) ;     //Display about box
		break;
	}
}




/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		displayChar
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Mike Zobac
--
--		PROGRAMMER:		Chris Sim/Mike Zobac
--
--		INTERFACE:		void displayChar(char charRead, PTTYINFO pinfo)
--
--		RETURNS:		void
--
--		NOTES:			Displays the characters passed by the Presentation Layer on the screen by writing the chars in to a buffer, and
--						displaying the chars based on the memory co-ordinates in that buffer.  The buffer position is offset by the position
--						of the verticle scroll bar.
--------------------------------------------------------------------------------------------------------------------------------------------*/

DWORD WINAPI  displayChars(LPVOID info) {

	PTTYINFO pinfo = (PTTYINFO)info;
	char charRead;
	int i;
	for(i = 0; i < _mbslen(pinfo->printData); i++)
	{
		charRead = pinfo->printData[i];

		si.cbSize = sizeof (si) ;
		si.fMask  = SIF_ALL ;
		GetScrollInfo (pinfo->hwnd, SB_VERT, &si) ;
    
		// Save the position for comparison later on

		pinfo->iVertPos = si.nPos ;
   

        switch (charRead)
        {
            case '\x0A':                    // line feed
            break ;

            case '\x0D':                    // carriage return
            pinfo->xCaret = 0 ;
            ++pinfo->yCaret;

            if(pinfo->yCaret >= pinfo->cyBuffer)
                wmVscroll(pinfo->hwnd, SB_LINEDOWN, pinfo);

            if(pinfo->yCaret == pinfo->NUMLINES - 1) {

                memmove(pinfo->pBuffer, pinfo->pBuffer + pinfo->cxBuffer, sizeof(TCHAR) * pinfo->cxBuffer * (pinfo->cyBuffer - 1));
                clearLine('e', pinfo);
            }
            break ;

			case '\x08':                    // backspace
				if (pinfo->xCaret > 0)
				{
					-- pinfo->xCaret;
					// SendMessage (hwnd, WM_KEYDOWN, VK_DELETE, 1) ;
				}
				break ;

			case '\x07':                    // bell
				break ;


			default:
				if(pinfo->yCaret == pinfo->NUMLINES) {
					memmove(pinfo->pBuffer, pinfo->pBuffer + pinfo->cxBuffer, sizeof(TCHAR) * pinfo->cxBuffer * (pinfo->cyBuffer - 1));
					clearLine('e', pinfo);
					--pinfo->yCaret;
            }

            BUFFER (pinfo->xCaret, pinfo->yCaret) = (TCHAR) charRead ;  // write char to position in buffer

            hdc = GetDC (pinfo->hwnd) ;

            SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
                dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

            TextOut (hdc, pinfo->xCaret * pinfo->cxChar, (pinfo->yCaret - pinfo->iVertPos) * pinfo->cyChar,
                & BUFFER (pinfo->xCaret, pinfo->yCaret), 1) ;



            DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
            ReleaseDC (pinfo->hwnd, hdc) ;

            if (++pinfo->xCaret == pinfo->cxBuffer)
            {
                pinfo->xCaret = 0 ;

                if (++pinfo->yCaret == pinfo->cyBuffer) {
                    wmVscroll(pinfo->hwnd, SB_LINEDOWN, pinfo);
                }
            }
            break ;
        }
    }
	return 0;
}





/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		clearLine
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Mike Zobac
--
--		PROGRAMMER:		Mike Zobac
--
--		INTERFACE:		void clearLine(char direction, PTTYINFO pinfo)
--
--		RETURNS:		void
--
--		NOTES:			fills a designated space within the buffer with space characters, and displays them on the screen, effectively 
--						clearing the line to the left or right of the cursor, or clearing the entire line. The direction to clear is
--						designated by the char passed in to the function.
--------------------------------------------------------------------------------------------------------------------------------------------*/

void clearLine(char direction, PTTYINFO pinfo)
{
    int xTemp;
    
    hdc = GetDC (pinfo->hwnd) ;

    SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
        dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;
    
    switch(direction)
    {
        case 'l':       //  clear line left
        {
            for (xTemp = pinfo->xCaret; xTemp >= 0 ; xTemp--)
            {
                BUFFER (xTemp, pinfo->yCaret) = ' ' ;
                TextOut (hdc, xTemp * pinfo->cxChar, (pinfo->yCaret - pinfo->iVertPos) * pinfo->cyChar,
                & BUFFER (xTemp, pinfo->yCaret), 1) ;
            }
            break;
        }
        case 'r':  // clear line right
        {
            for(xTemp = pinfo->xCaret; xTemp <= pinfo->cxBuffer ; xTemp++)
            {
                BUFFER (xTemp, pinfo->yCaret) = ' ';
                TextOut (hdc, xTemp * pinfo->cxChar, (pinfo->yCaret - pinfo->iVertPos) * pinfo->cyChar,
                    & BUFFER (xTemp, pinfo->yCaret), 1) ;
            }
            break;
        }
        case 'e':       // clear entire line
        {
            for (xTemp = pinfo->cxBuffer; xTemp >= 0; xTemp--)
            {
                BUFFER (xTemp, pinfo->yCaret) = ' ' ;
                TextOut (hdc, xTemp * pinfo->cxChar, pinfo->yCaret * pinfo->cyChar,
                    & BUFFER (xTemp, pinfo->yCaret), 1) ;
            }
            break;
        }
    
    }
    DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
    ReleaseDC (pinfo->hwnd, hdc) ;
    return;

}





/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		wmPaint
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Mike Zobac
--
--		PROGRAMMER:		Mike Zobac
--
--		INTERFACE:		void wmPaint(HWND hwnd, PTTYINFO pinfo)
--
--		RETURNS:		void
--
--		NOTES:			Called by the WinProc whenever there is a message to repaint the screen, or a portion of the screen. 
--------------------------------------------------------------------------------------------------------------------------------------------*/

void wmPaint(HWND hwnd, PTTYINFO pinfo) {

    PAINTSTRUCT		ps ;
    int             x, y, i, iPaintBeg,iPaintEnd;

	
    hdc = BeginPaint (hwnd, &ps) ;


	// Get vertical scroll bar position

	si.cbSize = sizeof (si) ;
	si.fMask  = SIF_POS ;
	GetScrollInfo (hwnd, SB_VERT, &si) ;
	pinfo->iVertPos = si.nPos ;

	// Find painting limits

	iPaintBeg = max (0, pinfo->iVertPos + (ps.rcPaint.top / pinfo->cyChar)) ;
	iPaintEnd = min (pinfo->NUMLINES - 1,
		pinfo->iVertPos + (ps.rcPaint.bottom / pinfo->cyChar)) ;

	SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
		dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

	for (i = iPaintBeg ; i <= iPaintEnd ; i++)
	{
		y = (i - pinfo->iVertPos) ;

		TextOut (hdc, 0, y * pinfo->cyChar, & BUFFER(0,i), pinfo->cxBuffer) ;
	}

	DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
	EndPaint (hwnd, &ps) ;
}





/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		wmVscroll
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Mike Zobac
--
--		PROGRAMMER:		Chris Sim/Mike Zobac
--
--		INTERFACE:		void wmVscroll(HWND hwnd, WPARAM wParam, PTTYINFO pinfo)
--
--		RETURNS:		void
--
--		NOTES:			Called by the WinProc whenever there is a message regarding the verticle scroll bar.  Scrolls the text inside the 
--						client area of the window.
--------------------------------------------------------------------------------------------------------------------------------------------*/

void wmVscroll(HWND hwnd, WPARAM wParam, PTTYINFO pinfo) {

	si.cbSize = sizeof (si) ;
	si.fMask  = SIF_ALL ;
	GetScrollInfo (hwnd, SB_VERT, &si) ;

	// Save the position for comparison later on

	pinfo->iVertPos = si.nPos ;

	switch (LOWORD (wParam))
	{
	case SB_TOP:
		si.nPos = si.nMin ;
		break ;

	case SB_BOTTOM:
		si.nPos = si.nMax ;
		break ;

	case SB_LINEUP:
		si.nPos -= 1 ;
		break ;

	case SB_LINEDOWN:
		si.nPos += 1;
			//(*pinfo->pBuffer % pinfo->cyBuffer);
		//(pinfo->pBuffer, pinfo->pBuffer + pinfo->cxBuffer, sizeof(TCHAR) * pinfo->cxBuffer * (pinfo->cyBuffer - 1));
		break ;

	case SB_PAGEUP:
		si.nPos -= si.nPage ;
		break ;

	case SB_PAGEDOWN:
		si.nPos += si.nPage ;
		break ;

	case SB_THUMBTRACK:
		si.nPos = si.nTrackPos ;
		break ;

	default:
		break ;         
	}
	// Set the position and then retrieve it.  Due to adjustments
	//   by Windows it may not be the same as the value set.

	si.fMask = SIF_POS ;
	SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
	GetScrollInfo (hwnd, SB_VERT, &si) ;

	// If the position has changed, scroll the window and update it

	if (si.nPos != pinfo->iVertPos)
	{                    
		ScrollWindow (hwnd, 0, pinfo->cyChar * (pinfo->iVertPos - si.nPos), 
			NULL, NULL) ;
		UpdateWindow (hwnd) ;
    }
    return;

}






/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		wmSize
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Mike Zobac
--
--		PROGRAMMER:		Mike Zobac
--
--		INTERFACE:		void wmSize(HWND hwnd, UINT message, LPARAM lParam, PTTYINFO pinfo)
--
--		RETURNS:		void
--
--		NOTES:			This is called by the winProc whenever the window is resized.  This Function sets the size of the client X and Y 
--						limits, and initializes the print buffer based on those sizes.
--------------------------------------------------------------------------------------------------------------------------------------------*/

void wmSize(HWND hwnd, UINT message, LPARAM lParam, PTTYINFO pinfo) {

	int x, y;
	
	// obtain window size in pixels

	if (message == WM_SIZE)
	{
		pinfo->cxClient = LOWORD (lParam) ;
		pinfo->cyClient = HIWORD (lParam) ;
	}
	
    // calculate window size in characters

	pinfo->cxBuffer = max (1, pinfo->cxClient / pinfo->cxChar) ;
	pinfo->cyBuffer = max (1, pinfo->cyClient / pinfo->cyChar) ;

	pinfo->NUMLINES = pinfo->cyBuffer + 700 ;

    // allocate memory for buffer and clear it
    
    if (pinfo->pBuffer != NULL)
        free (pinfo->pBuffer) ;

    pinfo->pBuffer = (TCHAR *) malloc (pinfo->cxBuffer * pinfo->NUMLINES * sizeof (TCHAR)) ;

	for (y = 0 ; y < pinfo->NUMLINES ; y++)
		for (x = 0 ; x < pinfo->cxBuffer ; x++)
			BUFFER(x,y) = ' ' ;

	// Set vertical scroll bar range and page size

	si.cbSize = sizeof (si) ;
	si.fMask  = SIF_RANGE | SIF_PAGE ;
	si.nMin   = 0 ;
	si.nMax   = pinfo->NUMLINES - 1 ;
	si.nPage  = pinfo->cyClient / pinfo->cyChar ;
	SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;

	// set caret to upper left corner

	pinfo->xCaret = 0 ;
	pinfo->yCaret = 0 ;

	//if (hwnd == GetFocus ())
		//SetCaretPos (pinfo->xCaret * pinfo->cxChar, pinfo->yCaret * pinfo->cyChar) ;
    
    InvalidateRect (hwnd, NULL, TRUE) ;
    return;
}





/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		wmCreate
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Chris Sim
--
--		PROGRAMMER:		Chris Sim
--
--		INTERFACE:		void wmCreate(HWND hwnd, PTTYINFO pinfo)
--
--		RETURNS:		void
--
--		NOTES:			This function is called by the WinProc when the main function creates the window.  This function initializes the
--						port name, sets the average size of the characters, and calls the Physical Layer to initialize the port.  It then 
--						begins the thread owned by the Session Layer for reading the port.
--------------------------------------------------------------------------------------------------------------------------------------------*/

void wmCreate(HWND hwnd, PTTYINFO pinfo, LPCREATESTRUCT hinst) {
    
    TEXTMETRIC      tm ;
	HWND			dlghwnd;
	
    initializePdata(pinfo);
	
    hdc = GetDC (hwnd) ;

    pinfo->hwnd = hwnd;

    SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
		dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

	GetTextMetrics (hdc, &tm) ;
	pinfo->cxChar = tm.tmAveCharWidth ;
	pinfo->cyChar = tm.tmHeight ;

        // Open port and set DCB

    pinfo->hPort = initializePort(pinfo);
    setUserPrefs(pinfo);

	
    DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
	ReleaseDC (hwnd, hdc) ;
	dlghwnd = CreateDialog(hinst->hInstance, MAKEINTRESOURCE(IDD_DLGFIRST), hwnd, reinterpret_cast<DLGPROC>(DlgProc));

	pinfo->dlghwnd = dlghwnd;

	SendMessage(dlghwnd, WM_CREATE, (WPARAM)pinfo, NULL);

	InvalidateRect(dlghwnd, NULL, TRUE); 
}



/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		wmInputLang
--
--		DATE:			October 24, 2011
--
--		DESIGNER:		Chris Sim
--
--		PROGRAMMER:		Chris Sim
--
--		INTERFACE:		void wmInputLang(WPARAM wParam)
--
--		RETURNS:		void
--
--		NOTES:			Sets the character set of the language to be displayed on the screen.  This is called by the WinProc when it is
--						passed a WM_INPUTLANGUAGE message.
--------------------------------------------------------------------------------------------------------------------------------------------*/

void wmInputLang(WPARAM wParam) {
	dwCharSet = wParam ;
}


/*-------------------------------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		Initialize Pdata
--
--		DATE:			November 28, 2011
--
--		DESIGNER:		Mike Zobac
--
--		PROGRAMMER:		Mike Zobac
--
--		INTERFACE:		void initializePdata(PTTYINFO pdata)
--
--		RETURNS:		void
--
--		NOTES:			Initializes the values of the "global" data storded in the PTTYINFO struct.
--------------------------------------------------------------------------------------------------------------------------------------------*/

void initializePdata(PTTYINFO pinfo) 
{
    
    pinfo->portName = "COM1";
    pinfo->ENQ = CreateEvent(NULL, FALSE, FALSE, TEXT("ENQ")); 
    pinfo->ACK = CreateEvent(NULL, FALSE, FALSE, TEXT("ACK")); 
	pinfo->frameBuilt = CreateEvent(NULL, FALSE, FALSE, TEXT("FrameBuilt"));
	pinfo->FrameToSend = CreateEvent(NULL, TRUE, FALSE, TEXT("FrameToSend"));
	pinfo->wait = CreateEvent(NULL, FALSE, FALSE, TEXT("wait"));
    pinfo->delay = CreateEvent(NULL, FALSE, FALSE, TEXT("delay"));
    pinfo->pBuffer = NULL;
    pinfo->frameTypeExpected = '0';
    pinfo->frameTypeToWrite = '0';
    pinfo->frameTypeSent = '1';
	pinfo->endoftransmission = false;
	pinfo->receiving = false;
    pinfo->num_PacketsTransfered = 0;
	pinfo->receivedLastFrame = false;
	pinfo->num_PacketsTransfered = 0;
	pinfo->num_PacketsReceived = 0;
	pinfo->num_AcksSent = 0;
	pinfo->num_AcksReceived = 0;
	pinfo->num_EnqsSent = 0;
	pinfo->num_EnqsReceived = 0;
	pinfo->num_PER = 0;
	pinfo->num_CorruptPacketsReceived = 0;
	pinfo->num_CorruptPacketsSent = 0;
	pinfo->num_DuplicatePacketsReceived = 0;
	pinfo->num_DuplicatePacketsSent = 0;
}
